﻿@{
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();
}
@Html.DevExpress().GridView(

    settings =>
    {
        settings.Name = "GridView2";
        settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartialView2His" };



        //settings.CommandColumn.Visible = true;
        //settings.CommandColumn.Width = 80;

        settings.Settings.ShowFilterRow = true;
        settings.Settings.ShowFilterRowMenu = true;
        settings.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
        settings.SettingsBehavior.AllowSelectByRowClick = true;
        settings.CommandColumn.ShowSelectCheckbox = true;
        //settings.ClientSideEvents.SelectionChanged = "SelectionChanged";
        settings.CommandColumn.ShowClearFilterButton = true;
        settings.CommandColumn.SelectAllCheckboxMode = GridViewSelectAllCheckBoxMode.Page;

        settings.KeyFieldName = "SugNum";
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        settings.SettingsPager.PageSize = 20;
        settings.SettingsPager.PageSizeItemSettings.Visible = true;
        settings.SettingsPager.PageSizeItemSettings.Caption = "页大小";
        settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };
        settings.SettingsPager.Summary.Text = "当前页{0} 总页数 {1}";

        settings.Settings.VerticalScrollBarMode = ScrollBarMode.Auto;
        settings.Settings.HorizontalScrollBarMode = ScrollBarMode.Auto;
        settings.Settings.VerticalScrollableHeight = 500;//

        settings.ControlStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
        settings.ControlStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
        settings.ControlStyle.BorderBottom.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);

        //settings.CustomJSProperties = (s, e) => {
        //    MVCxGridView grid = s as MVCxGridView;
        //    if(grid == null) return;

        //    e.Properties["cpVisibleRowCount"] = grid.VisibleRowCount;
        //    e.Properties["cpCurrentPageSelectsRow"] = GetCurrentPageSelectsRow(grid);
        //};

        ////settings.ClientSideEvents.Init = "OnGridViewInit";
        //settings.ClientSideEvents.SelectionChanged = "OnGridViewSelectionChanged";
        ////settings.ClientSideEvents.EndCallback = "OnGridViewEndCallback";

        // DXCOMMENT: Configure grid's columns in accordance with data model fields
        settings.Columns.Add("VendorID", "公司ID").Width = 80;
        settings.Columns.Add("BuyerID", "采购员ID").Width = 60;
        settings.Columns.Add("SugNum", "建议编号").Width = 80;
        settings.Columns.Add("PartNum", "物料编码").Width = 100;
        settings.Columns.Add("RevisionNum", "物料版本").Width = 100;
        settings.Columns.Add("LineDesc", "物料名称").Width = 400;
        //settings.Columns.Add("UnitPrice", "单价", MVCxGridViewColumnType.TextBox).Width = 100;
        //settings.Columns.Add("XRelQty", "订单数量").Width = 100;
        settings.Columns.Add(c =>
        {
            c.FieldName = "DocUnitPrice";
            c.Caption = "单价";

            c.Width = 100;
            c.ReadOnly = true;
            c.EditorProperties().SpinEdit(sp =>
            {
                sp.DisplayFormatString = "N";
                sp.DisplayFormatInEditMode = true;
                sp.MinValue = 0;
            });
        });
        settings.Columns.Add(c =>
        {
            c.FieldName = "XRelQty";
            c.Caption = "订单数量";
            c.Width = 100;
            c.EditorProperties().SpinEdit(sp =>
            {
                sp.DisplayFormatString = "N";
                sp.NumberType = SpinEditNumberType.Integer;
                sp.MinValue = 0;

            });
        });
        settings.Columns.Add("IUM", "单位").Width = 40;
        settings.Columns.Add("OrderByDate", "订单日期", MVCxGridViewColumnType.DateEdit).Width = 100;
        settings.Columns.Add("DueDate", "需求日期", MVCxGridViewColumnType.DateEdit).Width = 100;
        //settings.Columns.Add("BuyerID", "采购员ID");
        settings.Columns.Add("CommentText", "备注").Width = 100;
        //settings.Columns.Add("CheckBox05", "已下单");


        settings.CustomJSProperties = (s, e) =>
        {
            ASPxGridView grid = (ASPxGridView)s;
            e.Properties["cpGridFilterExpression"] = grid.FilterExpression;
        };

    }).Bind(Model).GetHtml()


@*@functions {
    string GetCurrentPageSelectsRow(MVCxGridView grid) {
        string selectedRowsOnPage = "";
        foreach(var key in grid.GetCurrentPageRowValues("SugNum")) {
            if(grid.Selection.IsRowSelectedByKey(key))
                selectedRowsOnPage+=(key.ToString()+",");
        }
        if(selectedRowsOnPage.Length > 0)
        {
            selectedRowsOnPage = selectedRowsOnPage.Substring(0, selectedRowsOnPage.Length - 1);
        }
        //Console.WriteLine(selectedRowsOnPage);
        return selectedRowsOnPage;
    }
}*@

